package com.lmx.wuzhangshao.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.lmx.wuzhangshao.R;
import com.lmx.wuzhangshao.base.BaseFragment;
import com.lmx.wuzhangshao.ui.ServiceActivity;
import com.lmx.wuzhangshao.util.ToastUtil;
import com.lmx.wuzhangshao.widget.BannerPager;

import java.util.ArrayList;

/**
 * @author Leung
 * @date 2020/8/9 20:51
 */
public class HomeFragment extends BaseFragment {

    private ArrayList<Integer> picList = new ArrayList<>();
    private ViewHolder holder;

    public HomeFragment() {
        picList.add(R.drawable.topbg);
        picList.add(R.drawable.topbg);
        picList.add(R.drawable.topbg);
    }

    @Override
    public View initViews(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        holder = new ViewHolder(view);
        return view;
    }

    @Override
    public void initData() {
        holder.tvToolbarLeft.setCompoundDrawables(
                ContextCompat.getDrawable(mActivity, R.drawable.fill1_3), null, null, null);
        holder.tvToolbarTitle.setText(getString(R.string.app_name));
        holder.imgBtnToolbarRight.setImageResource(R.drawable.fill2_3);
        holder.imgBtnToolbarRight.setVisibility(View.VISIBLE);
        holder.imgBtnToolbarRight.setOnClickListener((v ->
                startActivity(new Intent(mActivity, ServiceActivity.class))));
        holder.bpHomeBanner.setImages(picList);
        holder.bpHomeBanner.setInterval(3500);
        holder.bpHomeBanner.start();
        holder.bpHomeBanner.setOnBannerListener(position ->
                ToastUtil.showToast(mActivity, "你点击了我，position：" + position));
    }

    static class ViewHolder {
        View rootView;
        TextView tvToolbarLeft;
        TextView tvToolbarTitle;
        ImageButton imgBtnToolbarRight;
        RelativeLayout rlToolbarContainer;
        BannerPager bpHomeBanner;

        ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvToolbarLeft = rootView.findViewById(R.id.tv_toolbar_left);
            this.tvToolbarTitle = rootView.findViewById(R.id.tv_toolbar_title);
            this.imgBtnToolbarRight = rootView.findViewById(R.id.imgBtn_toolbar_right);
            this.rlToolbarContainer = rootView.findViewById(R.id.rl_toolbar_container);
            this.bpHomeBanner = rootView.findViewById(R.id.bp_home_banner);
        }

    }
}
